document.addEventListener('DOMContentLoaded', function() {
    // 初始化导航栏
    initializeNavigation();
    
    // 设置当前活动项
    setActiveNavItem();
});

function initializeNavigation() {
    const navItems = document.querySelectorAll('.section_3');
    
    navItems.forEach(item => {
        // 添加鼠标进入效果
        item.addEventListener('mouseenter', function() {
            this.style.transform = 'translateX(5px)';
        });
        
        // 添加鼠标离开效果
        item.addEventListener('mouseleave', function() {
            this.style.transform = 'translateX(0)';
        });
        
        // 添加点击效果
        item.addEventListener('click', function() {
            // 移除其他项的活动状态
            navItems.forEach(nav => nav.classList.remove('active'));
            // 添加当前项的活动状态
            this.classList.add('active');
        });
    });
}

function setActiveNavItem() {
    // 获取当前页面路径
    const currentPath = window.location.pathname;
    
    // 定义路径和导航项ID的映射
    const pathToId = {
        '/': 'Option_bed_information',
        '/bed_information': 'Option_bed_information',
        '/addCase': 'Option_add_patient',
        '/requesting/deal_request': 'Option_deal_request',
        '/requesting/my_request': 'Option_my_request'
    };
    
    // 获取当前应该激活的导航项ID
    const activeId = pathToId[currentPath];
    
    if (activeId) {
        // 移除所有活动状态
        document.querySelectorAll('.section_3').forEach(item => {
            item.classList.remove('active');
        });
        
        // 添加当前项的活动状态
        const activeItem = document.getElementById(activeId)?.closest('.section_3');
        if (activeItem) {
            activeItem.classList.add('active');
        }
    }
}

// 添加页面切换动画
function navigateTo(url) {
    // 添加页面退出动画
    document.body.style.opacity = '0';
    setTimeout(() => {
        window.location.href = url;
    }, 300);
}

// 监听后退/前进按钮
window.addEventListener('popstate', function() {
    setActiveNavItem();
});

// 页面加载完成后的动画
window.addEventListener('load', function() {
    document.body.style.opacity = '1';
});

